// author： sherlongqu
#include "HX711.h"



const int LOADCELL_DT_PIN = 12;
const int LOADCELL_SCK_PIN = 13;
const int ledPin = 11;
int val = 20;

HX711 scale;

void setup() {
  pinMode(ledPin, OUTPUT);
  Serial.begin(38400);
  Serial.println("HX711 Demo");
  scale.begin(LOADCELL_DT_PIN, LOADCELL_SCK_PIN);
  scale.set_scale(2280.f);                      // this value is obtained by calibrating the scale with known weights; see the README for details
  scale.tare();				        // reset the scale to 0
}

void loop() {
  
  if((int)scale.get_units(10)>=0){
    if(val < (int)scale.get_units(10)){
      digitalWrite(ledPin, HIGH); //点亮小灯
      
      Serial.print((int)scale.get_units(10));
      Serial.println("g");
      scale.power_down();
    }
    else
      digitalWrite(ledPin, LOW); //熄灭小灯
  }
  Serial.print((int)scale.get_units(10));
  Serial.println("g");
}
